<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="format-detection" content="telephone=no">
    <meta name="description" content="">
    <meta http-equiv="x-dns-prefetch-control" content="on">

    <title>已就位-卸货点</title>
    <link href="../../css/css.css" rel="stylesheet" type="text/css">
    <script src="../../js/jquery-v1.11.2.min.js"></script>
    <script src="../../js/driver.js"></script>
    <script src="../../js/common.js"></script>
</head>
<body>
<section class="itemgroup mt10 p15">
    <div class="oneitem_xl" id="endAddr">
        <i class="iconfont mr5 red icon28">&#xe70c;</i>

    </div>
    <div class="oneitem_xl">
        <label class="gray mr5">联系人:</label>
        <span id="consignName"></span>
        <i class="iconfont rightsmallicon">&#xe6db;</i>
        <label class="right" id="consignMobile"></label>
    </div>
</section>
<section class="p15 subtitle_xl mt10">实际行驶距离</section>
<section class="itemgroup">
    <div class="wait_time">
        <span id="realDistince">0</span><span class="icon25">公里</span>
    </div>
</section>
<section class="sale_info_xl">实际费用可能因实际行驶里程/等候时间等因素差异</section>
<section class="bottomarea">
    <button type="button" class="btn bottomonebtn_xl" id="goonBid5" onclick="goonBid5()">到达卸货点</button>
</section>
<form id="dataForm">
    <input type="hidden" name="waybillId" id="waybillId">
    <input type="hidden" id="longitude" name="lon">
    <input type="hidden" id="latitude" name="lat">
</form>
<script type="text/javascript">
    $(function () {
        //token验证
        checkDriverToken();
    });
    var waybillId=0;
    $(document).ready(function () {
        waybillId = GetArgsFromHref("waybillId");
        var url = _global.serverHost + "/driver/goon_bid4.htm";
        var data = {waybillId: waybillId};
        _callAjaxRequest(url, data, startBidBack);

        $("#waybillId").val(waybillId);

        function startBidBack(data) {
            $("#endAddr").html('<i class="iconfont mr5 red icon28">&#xe70c;</i>' + data.waybill.endAddr);
            $("#consignName").html(data.waybill.consignName);
            $("#consignMobile").html(data.waybill.consignMobile);
            $("#costTime").html(data.costTime);
        }
    });

    function goonBid5() {
        var url = _global.serverHost + "/driver/check_goon_bid4.htm";
        var data = {waybillId: waybillId,driverUuid: getCookie("driverUuid")};
        _callAjaxRequest(url, data, goonBid5Back);
    }

    function goonBid5Back(data) {
        if (data.code == "1") {
            window.location.href = "../start_bid/goon_bid5.html?waybillId=" + data.waybillId;
        } else {
            alert(data.message);
        }
    }

    window.setInterval("getRealDistince()", 1000);
    function getRealDistince() {
        $.ajax({
            type: "POST",
            url: _global.serverHost + "/driver/get_real_distince.htm",
            data: {waybillId: $("#waybillId").val()},
            contentType: "application/x-www-form-urlencoded;charset=UTF-8",
            success: function (data) {
                if (data != null && data > 0) {
                    $("#realDistince").html(data);
                }
            }
        });
    }

    function uploadLocation() {
        var loc = "31.12345,121.23456";
        if (typeof javaHandler != "undefined") {
            loc = javaHandler.getCurrentLocation();
        }
        var locs = loc.split(",");
        $("#longitude").val(locs[1]);
        $("#latitude").val(locs[0]);
        var json_data = {
            waybillId: waybillId,
            lat: locs[0],
            lon: locs[1],
            driverUuid: getCookie("driverUuid"),
            comment: "定时定位"
        };

        if (_global.sendPost == "0") {
            _callAjaxRequest(_global.serverHost + '/driver/location.htm', json_data, function (data) {
                console.log(JSON.stringify(data));
            });
        } else {
            callHTTPRequestLogon(JSON.stringify(json_data));//app调用
        }
        var timer = setTimeout("uploadLocation()", 60000);//60秒
    }
</script>
</body>
</html>